﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Xml.Linq;
using System.Xml.Serialization;
using System.IO;

namespace Zombie_Demo.User_Interface
{
     public static class XML_Handler{
        public static void Serialize<T>(T t, string filename) where T : class
        {
            XmlSerializer s = new XmlSerializer(typeof(T));
            TextWriter w = new StreamWriter(@filename+".xml");
            s.Serialize(w, t);
            w.Close();
        }

        public static T DeSerialize<T>(string xmlFilePath) where T : class
        {
             string file = Utilities.ContentLibrary.ContentFilePath + "XML\\" + xmlFilePath + ".xml";
             TextReader r = new StreamReader(file);
             XmlSerializer s = new XmlSerializer(typeof(T));
             object o = s.Deserialize(r);
             T t = (T)o;
             if (t is User_Interface.Frame)
             {
                  User_Interface.Frame f = (User_Interface.Frame)o;
                  f.SetElementsToParent();
                  o = (object)f;
             }
             t = (T)o;
             return t;
        }
     }
}

